package main

import (
	"blog/internal/database"
	"blog/internal/models"
	"blog/internal/pkg/password"
	"gorm.io/gorm"
	"time"
)

func main() {
	pwd, _ := password.GeneratePassword("yekern")
	u := models.User{
		ID:          0,
		Username:    "admin",
		Password:    pwd,
		Status:      1,
		LastLoginAt: nil,
		LastLoginIP: "127.0.0.1",
		CreatedAt:   time.Now(),
		UpdatedAt:   time.Now(),
	}
	err := database.GetDB().Transaction(func(tx *gorm.DB) error {
		// 插入用户数据
		if err := tx.Create(&u).Error; err != nil {
			return err
		}
		// 插入用户资料
		p := models.Profile{
			UID:       u.ID,
			Nickname:  "Admin",
			Avatar:    "",
			Email:     "yekern@163.com",
			Weibo:     "https://weibo.com/yekern",
			Github:    "https://github.com/yekern",
			Gitee:     "https://gitee.com/yekern",
			QQ:        "560762",
			Wechat:    "feng_0615",
			CreatedAt: time.Now(),
			UpdatedAt: time.Now(),
		}
		if err := tx.Create(&p).Error; err != nil {
			return err
		}
		return nil
	})
	if err != nil {

		return
	}

}
